import React from 'react';
import CommonList from 'src/components/CommonLists/list';
import { Button, message } from 'antd';
import services from 'src/services/api';
import Modal from 'src/components/Modal/index';

class ModelConfigList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'modelConfig';
    this.state = {
      applications: [],
      events: [],
    };
    this.operatorWidth = '200px';
    this.monitorButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          // disabled={record.deploy_status !== 0}
          onClick={() => {
            props.history.push(`/variable/model/config/${record.id || 0}/detail`);
            // props.history.push('/monitor/devOps/api?onlyModel=true&&service_id=' + record.service_id);
          }}
        >
          监控
        </Button>
      );
    };

    this.delButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.delete.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          删除
        </Button>
      );
    };
    this.btnGroup = [this.monitorButton, this.delButton];
  }

  // 删除时的参数
  getDeleteParam = (record) => {
    return { deploy_name: record.deploy_name };
  };

  delete(record) {
    Modal.open({
      title: '',
      isConfirm: true,
      width: '300px',
      content: '确定要删除?',
      isOkBtn: true,
      isCancelBtn: true,
      ok: () => {
        services[this.api].delete(this.getDeleteParam(record)).then((data) => {
          if (data.code === 0) {
            message.success(data.msg);
            this.props.queryList();
            Modal.close();
          } else {
            message.error(data.msg);
          }
        });
      },
      cancel: () => {
        Modal.close();
      },
    });
  }
}

export default ModelConfigList;
